package com.yinhai.project.config;

import com.yinhai.core.common.api.config.impl.ConfigManager;
import com.yinhai.core.common.api.config.impl.SysConfig;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

public class LoadTa3ProjectConfig implements InitializingBean,DisposableBean {
	
	private static Log logger = LogFactory.getLog(LoadTa3ProjectConfig.class);

	public void init() throws Exception {
		logger.info("开始加载ta3-project的主配置文件");
		ConfigManager.loadConfig("config");
		//配置文件是否分布式化,存放在zookeeper中
		if(SysConfig.getSysConfigToBoolean("isConfigDistribute",false)){
			ConfigManager.initDistributeConfig();
		}
		logger.info("加载ta3-project的主配置文件结束");
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		init();
	}

	@Override
	public void destroy() throws Exception {
		if(SysConfig.getSysConfigToBoolean("isConfigDistribute",false)){
			ConfigManager.destroy();
		}
	}

}
